package com.itheima.controller;

import com.itheima.common.Result;
import com.itheima.common.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


/**
 * UploadController
 *
 * @author liliudong
 * @version 1.0
 * @description 文件上传控制器
 * @date 2023/7/16 10:05
 */
@Slf4j
@RestController
public class UploadController {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    /**
     * 上传文件
     *
     * @param image
     * @param name
     * @param age
     * @return
     * @throws IOException
     */
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile image, String name, Integer age) throws IOException {
        String url = aliOSSUtils.upload(image);
        return Result.success(url);
    }
}
